package cn.edu.stu.syllabus.adapters;

import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.edu.stu.syllabus.R;
import cn.edu.stu.syllabus.base.BaseQuickClickAdapter;
import cn.edu.stu.syllabus.datas.Information;
import cn.edu.stu.syllabus.utils.DrawableTintUtils;

/**
 * Created by daidaijie on 2017/3/28.
 */

public class InformationAdapter extends BaseQuickClickAdapter<Information, InformationAdapter.ViewHolder> {

    private int mTitleMaxLength;

    @Override
    protected ViewHolder createBaseViewHolder(View view) {
        return new ViewHolder(view);
    }


    public InformationAdapter(List<Information> data, int titleMaxLength) {
        super(R.layout.item_information, data);
        mTitleMaxLength = titleMaxLength;
    }

    @Override
    protected void convert(ViewHolder helper, Information item) {
        StringBuilder sb = new StringBuilder(item.getTitle());
        int needSpaceNum = mTitleMaxLength - item.getTitle().length();
        for (int i = 0; i < needSpaceNum; i++) {
            sb.append("　");
        }
        helper.mTitleTextView.setText(sb.toString());
        helper.mDescTextView.setText(item.getDesc());

        Drawable icon = DrawableTintUtils.getTintDrawableByColorRes(item.getIcon(),
                R.color.colorTextSecondly);
        helper.mTitleTextView.setCompoundDrawablesWithIntrinsicBounds(
                icon, null, null, null
        );
    }

    public class ViewHolder extends BaseViewHolder {
        @Nullable
        @BindView(R.id.titleTextView)
        TextView mTitleTextView;
        @Nullable
        @BindView(R.id.descTextView)
        TextView mDescTextView;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
